package com.juyu.reader.pc.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.juyu.reader.pc.model.User;

/**
 * 判断用户是否登录，拦截器
 * @author wbf
 * 2019年5月30日
 */
public class UserInterceptor implements HandlerInterceptor {
	Logger logger = Logger.getLogger(UserInterceptor.class);

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
		// TODO Auto-generated method stub
		User user = (User) request.getSession().getAttribute(Constants.SYSTEM_SESSION_USER);
		if (user != null) {
			return true;
		}
		request.getRequestDispatcher("/user/toLogin").forward(request, response);
		return false;
	}
}
